using System.Text.Json.Serialization;

namespace Uantek.Device.Communication.Models
{
    /// <summary>
    /// 设备数据模型
    /// </summary>
    public class DeviceDataModel
    {
        /// <summary>
        /// 设备ID
        /// </summary>
        [JsonPropertyName("deviceId")]
        public string DeviceId { get; set; } = string.Empty;

        /// <summary>
        /// 设备名称
        /// </summary>
        [JsonPropertyName("deviceName")]
        public string DeviceName { get; set; } = string.Empty;

        /// <summary>
        /// 数据时间戳
        /// </summary>
        [JsonPropertyName("timestamp")]
        public DateTime Timestamp { get; set; } = DateTime.Now;

        /// <summary>
        /// 数据类型（传感器数据、状态数据、报警数据等）
        /// </summary>
        [JsonPropertyName("dataType")]
        public string DataType { get; set; } = string.Empty;

        /// <summary>
        /// 数据值集合
        /// </summary>
        [JsonPropertyName("dataValues")]
        public Dictionary<string, object> DataValues { get; set; } = new();

        /// <summary>
        /// 数据单位集合
        /// </summary>
        [JsonPropertyName("dataUnits")]
        public Dictionary<string, string> DataUnits { get; set; } = new();

        /// <summary>
        /// 数据质量（0-100，100表示最佳质量）
        /// </summary>
        [JsonPropertyName("quality")]
        public int Quality { get; set; } = 100;

        /// <summary>
        /// 原始数据（十六进制字符串）
        /// </summary>
        [JsonPropertyName("rawData")]
        public string? RawData { get; set; }

        /// <summary>
        /// 协议名称
        /// </summary>
        [JsonPropertyName("protocolName")]
        public string ProtocolName { get; set; } = string.Empty;

        /// <summary>
        /// 传输类型
        /// </summary>
        [JsonPropertyName("transportType")]
        public string TransportType { get; set; } = string.Empty;

        /// <summary>
        /// 扩展属性
        /// </summary>
        [JsonPropertyName("extendedProperties")]
        public Dictionary<string, object> ExtendedProperties { get; set; } = new();

        /// <summary>
        /// 数据来源（设备IP、串口号等）
        /// </summary>
        [JsonPropertyName("dataSource")]
        public string DataSource { get; set; } = string.Empty;

        /// <summary>
        /// 是否为报警数据
        /// </summary>
        [JsonPropertyName("isAlarm")]
        public bool IsAlarm { get; set; } = false;

        /// <summary>
        /// 报警级别（当IsAlarm为true时有效）
        /// </summary>
        [JsonPropertyName("alarmLevel")]
        public string? AlarmLevel { get; set; }

        /// <summary>
        /// 报警消息（当IsAlarm为true时有效）
        /// </summary>
        [JsonPropertyName("alarmMessage")]
        public string? AlarmMessage { get; set; }

        /// <summary>
        /// 协议版本
        /// </summary>
        [JsonPropertyName("protocolVersion")]
        public string? ProtocolVersion { get; set; }
    }
}